package web.servlets;

import domain.Account;
import domain.Diary;
import service.DialogService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @projectName: petStore
 * @package: web.servlets
 * @className: ViewDialogServlet
 * @author: suqianbei
 * @description: TODO
 * @date: 2021/11/4 12:31
 * @version: 1.0
 */
public class ViewDialogServlet extends HttpServlet {
     public static final String VIEW_DIALOG="/WEB-INF/jsp/dialog/Dialog.jsp";
     private  String name;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        name="localhost";
        HttpSession session=req.getSession();
        session.setAttribute("symbol",0);
        Account account=(Account)session.getAttribute("account");
        if(account!=null)
        {
            name=account.getUsername();
        }
        //判断是否登录

        DialogService dialogService=new DialogService();
        List<Diary> diaryList=dialogService.getDiaryByName(name);

        session.setAttribute("name",name);
        session.setAttribute("diaryList",diaryList);
        req.getRequestDispatcher(VIEW_DIALOG).forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
